package com.itmk.system.user.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itmk.system.permission.entity.Permission;
import com.itmk.system.permission.mapper.PermissionMapper;
import com.itmk.system.role.entity.Role;
import com.itmk.system.role.mapper.RoleMapper;
import com.itmk.system.user.entity.SysUser;
import com.itmk.system.user.mapper.SysUserMapper;
import com.itmk.system.user.service.UserService;
import com.itmk.utils.PageUtil;
import com.itmk.vo.req.UserReqVO;
import com.itmk.vo.resp.PageRespVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户Service实现类
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements UserService {

    @Autowired
    private PermissionMapper permissionMapper;
    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public SysUser getUserByUserName(String username) {
        QueryWrapper<SysUser> query = new QueryWrapper<>();
        query.lambda().eq(SysUser::getUsername,username);
        SysUser user = this.baseMapper.selectOne(query);
        return user;
    }

    @Override
    public SysUser findAllUserInfoByUsername(String username) {
        QueryWrapper<SysUser> query = new QueryWrapper<>();
        query.lambda().eq(SysUser::getUsername,username);
        SysUser user=this.baseMapper.selectOne(query);
        List<Permission> permissions=permissionMapper.getPermissionListByUserId(user.getId());
        return user;
    }

    @Override
    public SysUser findSimpleUserInfoById(long userId) {
        return this.baseMapper.selectById(userId);
    }

    @Override
    public SysUser findSimpleUserInfoByUsername(String username) {
        return null;
    }

    @Override
    public IPage<SysUser> getUserWithRoleList(IPage page, UserReqVO userReqVO) {
        return this.baseMapper.getUserWithRoleList(page,userReqVO);
    }


}
